< previous page page_26 next page >

Page 26
objects. That is, the purpose of the subordinate object (contained object) is to serve the aggregate object for some special purpose known only by the aggregate. In a stricter sense of aggregation, a composite object determines when an object comes into existence and when it goes out of existence. The lifetime of the composed object is dependent on the composite object. Whew! Let's look at the Sebring example again.
Note
Some more astute object technologists might dispute the definition of the terms aggregation, composition, and collection here. The finer points of these concepts are a matter of intense discussion in some circles. Nevertheless, the fundamental ideas are explained here for simplicity's sake and seldom create a huge problem in practice.

New Term: An aggregate object is composed of one or more objects that are an integral part of that composite object. Thus, a tree class is composed of branch objects, which are then composed of leaf objects. These branch and leaf objects are said to be tightly coupled to the tree object because if the tree dies, they die. A collection of objects holds references to one or more objects that are loosely coupled. That is, a collection can hold references to any kind of object, and the lifetime of those objects isn't dependent on the collection itself. You create collections by using the Collection type in Visual Basic.
Note
Of course, you can create a special collection class that serves as a wrapper to an object declared as
Collection. You can then customize this collection class to create and destroy objects as they are respectively added to and deleted from the collection. However, the wrapper class itself then begins to exhibit the behavior of an aggregate object more than a wrapper.

On further examination, have you noticed that the Sebring is actually composed of other objects? These objects include the tire, the steering wheel, the door, the window, the brake, headlights, and so on. You can say that the Sebring is an aggregate of all these objects. A collection of objectssometimes hard to identify in the real worldmight include the fuse box under the dashboard (another object) or under the hood (another object). Each fuse is an object, and the fuse box is a collection of fuse objects. A key method of each fuse would be to shut down a car's electrical system to avoid major problems.

 
< previous page page_26 next page >

If you like this book, buy it!